'use strict';

/**
 * copyright (c) 2017-2023 厦门风领科技有限公司
 * https://www.fengling.cn/
 * 
 * 初始化游戏推荐组件
 * zengbinsi
 * 2020-09-27
 */


import path from 'path';
import pathUtil from '../libs/utils/path-utils';
import { exec as spawn} from 'child_process';
import { callSequence } from '../libs/utils/function-call-seq';
const srcPath = pathUtil.getPathInTemplateAssets(path.join('bundles', 'framework', 'platform', 'game-recommend'));
const dstPath = pathUtil.getPathInAssets(path.join('bundles', 'Framework', 'Platform'));




// 初始化目录
const initDir = (callback?: Function) => {
    pathUtil.mkdirsSyncInAssets(path.join('bundles', 'framework', 'platform', 'game-recommend'), callback);
};


export const initFilePlatformGameRecommend = (callback?: Function) => {
    console.log(`[tool-box]import GameRecommend...`);

    return callSequence([initDir, (cb?: Function) => {
        const sh = `cp -rf ${srcPath} ${dstPath}`;
        const obj: any = spawn(sh);

        obj.stdout.on('data', (data: any) => {
            console.log('[tool-box]', 'import GameRecommend successed!', data);
        });

        obj.stderr.on('data', (err: any) => {
            console.error('[tool-box]', 'import GameRecommend failed!', err);
        });

        obj.on('exit', async (exitCode: any) => {
            console.log('[tool-box]', 'import GameRecommend successed!', exitCode);
            await pathUtil.refreshAsset(`db://assets/bundles/framework/platform/game-recommend/`);
            cb && cb();
        });
    }, callback]);
};